/*
 * Copyright 2009, Qys Creations 
 * 
 *  This file is part of Chameleon DB.
 *
 *  Chameleon DB is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Chameleon DB is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Chameleon DB.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * */


public class db_result_message implements db_interface_result{
	private int iMessageNum = 0;
	private String sMessageDescription = "";
	db_result_message(int iMes, String sMes) {
		iMessageNum = iMes;
		sMessageDescription = sMes;
	}
	
	public byte[] getBytes() {
		int iSize = 12 + sMessageDescription.length();

		byte[] bHeaders = ("200 OK QDBP/1.0\nlength: " + iSize + "\n\n").getBytes();
		db_bytes oOut = new db_bytes(iSize + bHeaders.length);

		oOut.write(bHeaders);

		// Message is an error
		oOut.write(db_util.DB_RESULT_MESSAGE);
		
		// Error number
		oOut.write(iMessageNum);
		oOut.write(sMessageDescription);
					
		return oOut.getBytes(); 
	}
}
